home *** CD-ROM | disk | FTP | other *** search
- /*****************************************************************************/
- /* (C) 1993,1994 R. NADE - M. GRANDCHAMP - All Rights Reserved */
- /*****************************************************************************/
- /* This source-code is NOT public domain nor Freeware, this is part of */
- /* 'The C Programming Package' which is Shareware. */
- /* If you use this code, please register and get a free Full-VGA version */
- /*****************************************************************************/
- /*-------------------*
- * CPPLHELP.C *
- * help manager *
- * text version. *
- *-------------------*/
-
- /* Included Files */
- # include <stdio.h>
- # include <io.h>
- # include <dos.h>
- # include <SYS\stat.h>
- # include <conio.h>
- # include <fcntl.h>
-
- /* Global Variables */
- extern int bm,i,j,k,l,m,n,x,xm,y,ym,z,beginningfile,endfile,pagemaxi;
- extern int colour1,colour2,colour3,colour4,colour5,pfhelp;
- extern long dephelp,depbeginning;
- extern unsigned char c1,nc1[],trashcan[],trashhelp[],trashelhelp[];
- extern unsigned char trashret[],work[];
-
- /*----------------*
- * OPEN HELP FILE *
- *----------------*/
- int open_help_file(offset)
- int offset;
- {
- /* Get the access path to the help file */
- strcpy(trashret,work);
- if(strlen(trashret)>3) strcat(trashret,"\\HELP.FIC");
- else strcat(trashret,"HELP.FIC");
- if(pfhelp>0) close(pfhelp);
- pfhelp=open(trashret,O_RDONLY | O_BINARY,S_IREAD|S_IWRITE);
- if (pfhelp==-1){
- textattr(colour5); gotoxy(1,25);
- cputs(" Can not open the help file "); sound3();
- wait_for_a_key(); return(0);
- }
- /* We put the file pointer approximatively at the location of */
- /* the first help screen concerned by this call */
- /* If we passed 0, we put the pointer at the beginning of the */
- /* file, else we go forward in the file 936 bytes further and */
- /* this the number of necessary times. So we avoid a too long */
- /* waiting because of the search of the first help screen in */
- /* the file. */
- /* NB : 936 bytes is the size of an help screen. */
- if(offset==0) dephelp=0L;
- else{
- dephelp=offset*936L;
- }
- return(1);
- }
- /*------------*
- * CHECK PAGE *
- *------------*/
- int check_page(page)
- int page;
- {
- /* We check if the page number written in the help */
- /* screen is the good one. */
- /* We do not modify file pointer, so we will not have */
- /* to correct it, but we go backward at 74 bytes of the */
- /* beginning of this page */
- dephelp+=112; nc1[3]=0x00;
- lseek(pfhelp,dephelp,0); read(pfhelp,nc1,3);
- n=atoi(nc1);
- dephelp-=112; lseek(pfhelp,dephelp,0);
- if(n==page) return(1);
- else return(0);
- }
- /*-------------------*
- * FIND FIRST SCREEN *
- *-------------------*/
- int find_first_screen(refhelp,page)
- char refhelp[9];
- int page;
- {
- nc1[2]=0x00; lseek(pfhelp,dephelp,0);
- while(!eof(pfhelp)){
- read(pfhelp,trashhelp,8); i=strcmp(trashhelp,refhelp);
- /* If the header concern the asking, display it */
- if(i==0){
- if(page==0) return(1);
- else{
- k=check_page(page);
- if(k==1) return(1);
- else{
- /* else we test the next screen */
- dephelp+=936; lseek(pfhelp,dephelp,0);
- }
- }
- }
- else{
- /* else we test the next screen */
- dephelp+=936; lseek(pfhelp,dephelp,0);
- }
- }
- /* If we are here that is because we are at the end of the file */
- /* and we did not get the help screen : error */
- if(pfhelp>0) close(pfhelp);
- pfhelp=-1; sound3();
- textattr(colour5);
- gotoxy(41,4); cputs(" ");
- gotoxy(41,5); cputs(" ╔══════════════════════════════════╗ ");
- gotoxy(41,6); cputs(" ║ Sorry. No help for this subject. ║ ");
- gotoxy(41,7); cputs(" ║ Press any Key to quit ║ ");
- gotoxy(41,8); cputs(" ╚══════════════════════════════════╝ ");
- gotoxy(41,9); cputs(" ");
- wait_for_a_key(); return(0);
- }
- /*----------------------*
- * DISPLAY HELP SCREEN *
- *----------------------*/
- void display_help_screen()
- {
- /* Hide the mouse during the display */
- hide_the_mouse(); textattr(colour3);
- /* We choose to display the help screen on the right of the screen */
- /* over the help menu to make understand that those menus are not */
- /* available during the consultation of the help */
- for(i=2; i<25; i++){
- dephelp+=39;
- lseek(pfhelp,dephelp,0); read(pfhelp,trashelhelp,39);
- gotoxy(42,i); cputs(trashelhelp);
- }
- /* Put the file pointer on the first line */
- /* And show the mouse */
- dephelp-=897; show_the_mouse();
- if(beginningfile==1){
- sound3(); textattr(colour5);
- gotoxy(44,2); cputs(" ATTENTION: beginning of help ");
- beginningfile=0; endfile=0;
- }
- if(endfile==1){
- sound3(); textattr(colour5);
- gotoxy(44,2); cputs(" ATTENTION: end of help ");
- beginningfile=0; endfile=0;
- }
- }
- /*-----------------------*
- * CHOICE FOLLOWING HELP *
- *-----------------------*/
- int choice_following_help()
- {
- /* Waiting for a key or a mouse button */
- while(1){
- if(kbhit()){
- /* If we pressed a key */
- c1=getch();
- if(c1>0){
- /* We pressed a standard key */
- if((c1==32)||(c1==13)||(c1==67)||(c1==99)){
- /* <Space> <Enter> <C> <c> Next page */
- return(1);
- }
- if((c1==8)||(c1==82)||(c1==114)){
- /* <Back space> <R> <r> Previous page */
- return(2);
- }
- if((c1==27)||(c1==81)||(c1==113)){
- /* <Esc> <Q> <q> quit */
- return(3);
- }
- }
- else{
- /* key code on 2 bytes */
- c1=getch();
- if((c1==77)||(c1==80)){
- /* Right or Down arrow : Next page */
- return(1);
- }
- if((c1==75)||(c1==72)){
- /* Up or Left arrow = Previous page */
- return(2);
- }
- }
- }
- /* Else test the mouse */
- get_mouse_state();
- if(bm==1){
- /* We pressed a mouse button */
- if((ym>21)&&(ym<25)){
- if((xm>42)&&(xm<56)) return(1);
- if((xm>56)&&(xm<68)) return(2);
- if((xm>68)&&(xm<80)) return(3);
- }
- /* If we clicked on another line or outside the reserved zone */
- /* quit help */
- return(3);
- }
- }
- }
- /*--------------*
- * DISPLAY HELP *
- *--------------*/
- void display_help(refhelp,offset,page,nbpages)
- char refhelp[9];
- int offset,page,nbpages;
- {
- pagemaxi=page+nbpages-1;
- save_help_screen(); i=open_help_file(offset);
- if(i==0){
- hide_the_mouse(); restore_help_screen();
- show_the_mouse(); return;
- }
- trashhelp[8]=0x00; refhelp[8]=0x00;
- trashelhelp[39]=0x00; i=find_first_screen(refhelp,page);
- if(i==0){
- hide_the_mouse(); restore_help_screen();
- show_the_mouse(); return;
- }
- beginningfile=0; endfile=0;
- depbeginning=dephelp; lseek(pfhelp,dephelp,0);
- while(!eof(pfhelp)){
- read(pfhelp,trashhelp,8); i=strcmp(trashhelp,refhelp);
- /* If the screen matches, we display it after verifying that */
- /* if required, the page number matches too */
- if(i==0){
- if(page==0) display_help_screen();
- else{
- k=check_page(page);
- if(k==1) display_help_screen();
- else{
- /* Else we are after the last page */
- endfile=1; dephelp-=936;
- display_help_screen();
- }
- }
- }
- else{
- /* If the header does not match anymore, we are at the end */
- /* we note this end, we display this. Then we go back to the */
- /* previous screen */
- endfile=1; dephelp-=936;
- display_help_screen();
- }
- /* If there are several pages, we increment */
- if(page>0){
- /* We precised one or more pages */
- if(page<pagemaxi) page++;
- }
- /* We wait the user's choice */
- /* 1 Next page, 2 Previous page, 3 Quit */
- j=choice_following_help();
- /* If we go on with the next screen */
- if(j==1) dephelp+=936;
- if(j==2){
- /* If we want to go back to the previous screen */
- dephelp-=936;
- if(dephelp<0){
- /* We are before the header */
- dephelp=0L; beginningfile=1;
- }
- if(dephelp<=depbeginning){
- /* We are back before the beginning of the first screen */
- /* that concerns the wanted help */
- dephelp=depbeginning; beginningfile=1;
- }
- }
- if(j==3){
- /* If we want to quit */
- if(pfhelp>0) close(pfhelp);
- pfhelp=-1;
- hide_the_mouse(); restore_help_screen();
- show_the_mouse(); return;
- }
- lseek(pfhelp,dephelp,0);
- if(eof(pfhelp)){
- /* We note the end of the file and we put the file pointer */
- /* to the beginning of the last valid screen */
- dephelp-=936; lseek(pfhelp,dephelp,0);
- endfile=1;
- }
- }
- }
- /* End of the main program supplement */
-